package com.softserveinc.autorent.manager;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import com.softserveinc.autorent.model.Car;

@Stateless
public class CarEJB extends AbstractEJB<Car> {

	@PersistenceContext(unitName = "jpa")
	private EntityManager em;

	@Override
	public EntityManager getEntityManager() {
		return em;
	}

	@Override
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}
	
	public CarEJB() {
		super(Car.class);
	}
/*@NamedQuery(name = "Car.findAll", query = "SELECT c FROM Car c"),
@NamedQuery(name = "Car.findById", query = "SELECT c FROM Car c WHERE c.id = :id"),
@NamedQuery(name = "Car.findAllByCarModelId", query = "SELECT c FROM Car c WHERE c.carModel.id = :id"),
@NamedQuery(name = "Car.findAllByCarVendorId", query = "SELECT c FROM Car c WHERE c.carModel.carVendor.id = :id"),
@NamedQuery(name = "Car.findAllByCarStatus", query = "SELECT c FROM Car c WHERE c.status = :status")
})*/	
	@Override
    public List<Car> findAll() {
        TypedQuery<Car> query = em.createNamedQuery("Car.findAll", Car.class);
        return query.getResultList();
    }
    public List<Car> findById(int id) {
        TypedQuery<Car> query = em.createNamedQuery("Car.findById", Car.class);
        query.setParameter("id", id);
        return query.getResultList();
    }
    public List<Car> findAllByCarModelId(int id) {
        TypedQuery<Car> query = em.createNamedQuery("Car.findAllByCarModel", Car.class);
        query.setParameter("id", id);        
        return query.getResultList();
    }
    public List<Car> findAllByCarVendorId(int id) {
        TypedQuery<Car> query = em.createNamedQuery("Car.findAllByCarVendor", Car.class);
        query.setParameter("id", id);        
        return query.getResultList();
    }
    public List<Car> findAllByCarStatus(String status) {
        TypedQuery<Car> query = em.createNamedQuery("Car.findAllByCarStatus", Car.class);
        query.setParameter("status", status);
        return query.getResultList();
    }    
}
